/*
*  Copyright 2019-2023 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.service.impl;

import me.zhengjie.domain.TrainDycgksl;
import me.zhengjie.domain.TrainDycxsjy;
import me.zhengjie.utils.FileUtil;
import lombok.RequiredArgsConstructor;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import me.zhengjie.service.TrainDycgkslService;
import me.zhengjie.domain.vo.TrainDycgkslQueryCriteria;
import me.zhengjie.mapper.TrainDycgkslMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import me.zhengjie.utils.PageUtil;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import me.zhengjie.utils.PageResult;

/**
* @description 服务实现
* @author huangwencong
* @date 2024-10-06
**/
@Service
@RequiredArgsConstructor
public class TrainDycgkslServiceImpl extends ServiceImpl<TrainDycgkslMapper, TrainDycgksl> implements TrainDycgkslService {

    private final TrainDycgkslMapper trainDycgkslMapper;

    @Override
    public TrainDycgksl findOne(Long trainId, Long trainItemId) {
        return trainDycgkslMapper.findOne(trainId, trainItemId);
    }

    @Override
    public PageResult<TrainDycgksl> queryAll(TrainDycgkslQueryCriteria criteria, Page<Object> page){
        return PageUtil.toPage(trainDycgkslMapper.findAll(criteria, page));
    }

    @Override
    public List<TrainDycgksl> queryAll(TrainDycgkslQueryCriteria criteria){
        return trainDycgkslMapper.findAll(criteria);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void create(TrainDycgksl resources) {
        save(resources);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void update(TrainDycgksl resources) {
        TrainDycgksl trainDycgksl = getById(resources.getId());
        trainDycgksl.copy(resources);
        saveOrUpdate(trainDycgksl);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteAll(List<Long> ids) {
        removeBatchByIds(ids);
    }

    @Override
    public void download(List<TrainDycgksl> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (TrainDycgksl trainDycgksl : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("训练ID", trainDycgksl.getTrainId());
            map.put("训练前地面(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlqDm());
            map.put("吸氧排氮(5500m)(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl5500Xypd());
            map.put("5500m即刻(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl5500());
            map.put("5500m 20min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlh550060());
            map.put("5500m 120min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlh5500120());
            map.put("5500m 180min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlh5500180());
            map.put("5500m 240min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlh5500240());
            map.put("5500m 300min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlh5500300());
            map.put("7000m 即刻(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000());
            map.put("7000m 20min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl700020());
            map.put("7000m 40min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl700040());
            map.put("7000m 60min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl700060());
            map.put("7000m 80min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl700080());
            map.put("7000m 100min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000100());
            map.put("7000m 120min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000120());
            map.put("7000m 140min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000140());
            map.put("7000m 160min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000160());
            map.put("7000m 180min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000180());
            map.put("7000m 200min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000200());
            map.put("7000m 220min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000220());
            map.put("7000m 240min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000240());
            map.put("7000m 260min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000260());
            map.put("7000m 280min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000280());
            map.put("7000m 300min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000300());
            map.put("7000m 320min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000320());
            map.put("7000m 340min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000340());
            map.put("7000m 360min(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXl7000360());
            map.put("训练后地面(血氧饱和|心率|呼吸|血压)", trainDycgksl.getXlhDm());
            map.put("主观症状(症状id1|症状id2|...|其他)", trainDycgksl.getFeels());
            map.put("书写表现", trainDycgksl.getSxbx());
            map.put("结果判定(0:优秀,1:良好,2:合格,3:不合格)", trainDycgksl.getResult());
            map.put("建议", trainDycgksl.getJy());
            map.put("记录日期", trainDycgksl.getDate());
            map.put("记录人", trainDycgksl.getCreateBy());
            map.put("创建时间", trainDycgksl.getCreateTime());
            map.put("更新时间", trainDycgksl.getUpdateTime());
            map.put("训练项目ID", trainDycgksl.getTrainItemId());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}